﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Xml;
//using System.Xml.Schema;
//using System.Xml.Serialization;
using Cofe.Core;
using Cofe.Core.Property;

namespace Cofe.Web.Models
{
    public class EntryViewModel
    {
        #region Constructor

        public EntryViewModel()
        {

        }

        protected EntryViewModel(ICofeSystemInfo entry)
        {
            _entry = entry;
            //ParseName = entry.Properties.Behaviors.GetProperty<string>(CofeProperties.FullParseName);
            //var supportedProps = entry.Properties.Behaviors.GetSupportedProperties();
            //foreach (var prop in supportedProps)
            //{
            //    if (DecoratorExtension.HasAlias(prop) && !DecoratorExtension.IsAction(prop))
            //    {
            //        string propStr = DecoratorExtension.getAlias(prop);
            //        object propVal = entry.Properties.Behaviors.GetProperty(prop).Value;

            //        if (propVal != null)
            //            _properties.Add(propStr, propVal.ToString());

            //    }                
            //}
        }


        public static EntryViewModel FromEntry(ICofeSystemInfo entry)
        {
            return new EntryViewModel(entry);
        }

        public static EntryViewModel FromPath(string path)
        {
            var entry = EntryFE.TryParsePathAsync(path).Result;
            if (entry != null)
                return new EntryViewModel(entry);
            else return new EntryViewModel();
        }

        #endregion

        #region Methods

        public string ParseName { get { return _entry.Properties.Behaviors.GetProperty<string>(CofeProperties.FullParseName); } }
        public string Name { get { return _entry.Properties.Behaviors.GetProperty<string>(CofeProperties.Name); } }
        public string Label { get { return _entry.Properties.Behaviors.GetProperty<string>(CofeProperties.Label); } }
        //public string ParseName { get; set; }
        public ICofeSystemInfo Entry { get { return _entry; } }
        public Dictionary<string, string> Properties { get { return _properties; } }

        #endregion

        #region Data

        #endregion

        #region Public Properties

        ICofeSystemInfo _entry;
        Dictionary<string, string> _properties = new Dictionary<string, string>();

        #endregion



    }

    public class EntryViewModel<T> : EntryViewModel where T : ICofeSystemInfo
    {
        #region Constructor

        protected EntryViewModel(T entry)
            : base(entry)
        {
            _entryT = entry;
        }

        public static EntryViewModel<T> FromEntry(T entry)
        {
            return new EntryViewModel<T>(entry);
        }

        #endregion

        #region Methods

        #endregion

        #region Data

        T _entryT;

        #endregion

        #region Public Properties

        public T EntryTyped { get { return _entryT; } }

        #endregion
    }
}
